<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="码头代码" prop="dock">
        <el-col :xs="12" :sm="6" :md="6" :lg="3"  :xl="3">
          <el-input v-model="form.dock"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="泊位代码" prop="berth">
        <el-col :xs="12" :sm="6" :md="6" :lg="3"  :xl="3">
          <el-input v-model="form.berth"></el-input>
        </el-col>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="setdevlocation">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
    export default {
        name: "devlocation",
      data:function () {
        var checkCode = (rule, value, callback) => {
          console.log(value);
          // debugger
          var reg=/^[0-9a-zA-Z]{1,10}$/
          if (!reg.test(value)) {
            return callback(new Error('英文 数字 1~10位'));
          }else{
            callback();
          }
        };
        return{
          form: {
            dock: '',
            berth: ''
          },
          rules: {
            dock: [
              { validator: checkCode, trigger: 'blur' }
            ],
            berth: [
              { validator: checkCode, trigger: 'blur' }
            ]
          }
        }
      },methods:{
        getdevlocation:function(){
          var _this=this
          _this.postAjax({
            method:'getdevlocation',
            params:{}
          }).then(function (res) {
            console.log(res);
            if(res.result==0){
              var data=res.params
              // debugger
              _this.form.dock=data.dock
              _this.form.berth=data.berth
            }else{
              _this.tips(res.errorInfo.detail,'error')
            }
          }).catch(function (err) {
            console.log(err);
            _this.tips(res.errorInfo.detail,'error')
          }).finally(function (fn) {
            console.log(fn);
          })
        },
        setdevlocation:function () {
          var _this=this
          this.$refs['form'].validate(function (valid) {
            if (valid) {
              _this.loading=true
              _this.postAjax({
                method:'setdevlocation',
                params:{
                  berth:_this.form.berth,
                  dock:_this.form.dock
                }
              }).then(function (res) {
                console.log(res);
                if(res.result==0){
                  _this.tips('保存成功','success')
                  // var data=res.params
                  // // debugger
                  // _this.form.ip=data.ip
                  // _this.form.gateway=data.gateway
                  // _this.form.mask=data.mask
                  // _this.form.dns1=data.dns1
                  // _this.form.dns2=data.dns2
                }else {
                  _this.tips(res.errorInfo.detail,'error')
                }
              }).catch(function (err) {
                console.log(err);
              }).finally(function (fn) {
                _this.loading=false
                console.log(fn);
              })
            } else {
              console.log('error submit!!');
              return false;
            }
          })
        }
      },mounted:function () {
        this.getdevlocation()
      }
    }
</script>

<style scoped>

</style>
